package com.lhkj.ct.admin.modules.questionnaire.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.psychology.model.vo.ViewAnswerVo;
import com.lhkj.ct.meta.modules.questionnaire.model.entity.TblQnrResult;
import com.lhkj.ct.meta.modules.questionnaire.service.QnrResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 问卷作答记录 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-10-26
 */
@RestController
@RequestMapping("api/plat/qnr/answer/record")
@Api(tags = {"5.3作答记录"})
@Validated
public class QnrResultController {

    @Resource
    private QnrResultService qnrResultService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "列表查询")
    @GetMapping("list")
//    //@RequiresPermissions(value = {"patient:unit:all"}, logical = Logical.OR)
    public ActionResult<IPage<TblQnrResult>> selectPatUnitPage(TblQnrResult result, PageQuery pageQuery) {
        return ActionResult.success(qnrResultService.selectQnrResultPage(result, pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查看")
    @GetMapping("{rId}/get")
//    //@RequiresPermissions(value = {"patient:unit:all"}, logical = Logical.OR)
    public ActionResult<ViewAnswerVo> get(@PathVariable String rId) {
        return ActionResult.success(qnrResultService.viewAnswer(rId));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "导出",  produces = "application/octet-stream")
    @GetMapping("{rId}/export")
    public void export(@PathVariable String rId) {
        qnrResultService.export(rId);
    }

    @ApiOperationSupport(order = 4)
    @PostMapping("delete")
    @ApiOperation(value = "删除", notes = "支持批量")
    @Log(title = "作答记录", actionType = ActionType.DELETE)
    public ActionResult<Void> delete(@RequestBody @NotEmpty(message = "撤销的编号不能为空") List<String> ids) {
        int count = qnrResultService.removeByIds(ids);
        return ActionResult.success(String.format("操作成功，共撤销[%s]条记录", count));
    }
}
